//
//  DZDinningDetailViewController.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 14-12-15.
//  Copyright (c) 2014年 zouzhisheng. All rights reserved.
//

#import "DZDinningDetailViewController.h"

@interface DZDinningDetailViewController (){
    DZRestanutantDetailSubModel *subModel;
    float initHeight;
}

@end

@implementation DZDinningDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    initHeight=44;
    self.navigationController.navigationBarHidden=YES;
    if (SharedAppDelegate.home.tabBarController) {
        [SharedAppDelegate.home.tabBarController setTabBarHidden:YES];
    }
    [self navView];
    [self addTitle:@"餐厅详情"];
    [self loadData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)backAction:(UIButton *)bt{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)loadData{
    NSDictionary *dir=[NSDictionary dictionaryWithObjectsAndKeys:@"detail",@"act",self.sid,@"sid", nil];
    [[BaseService shareNetworkService] requestActivityParameters:dir DataSouce:self RequestType:Request_RestanutantDetail Block:^(__weak id data, NSError *error) {
        if (!error) {
            DZRestanutantDetailModel *model=data;
            subModel=model.subjectDetailInfo[0];
            [self loadSubView];
        }
        
    }];
}
-(void)loadSubView
{
    [self.view addSubview:self.listView];
}
-(UITableView *)listView
{
    if (!_listView) {
        _listView=[[UITableView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20) style:UITableViewStylePlain];
        _listView.delegate=self;
        _listView.dataSource=self;
        _listView.backgroundColor=[UIColor colorWithHexString:@"ECECEC"];
        _listView.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _listView;
}
#pragma mark-UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.isZhekou) {
        return 3;
    }else{
        return 2;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isZhekou) {
        switch (indexPath.row) {
            case  0:
            {
                static NSString *cellIdentifier=@"DZRoomDetailTableViewCell";
                DZRoomDetailTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
                if (!cell) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DZRoomDetailTableViewCell"  owner:self options:nil] lastObject];
                }
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                [cell loadData:subModel];
                return cell;
   
            }
                break;
            case  2:
            {
                static NSString *cellIdentifier=@"DZDeailDownTableViewCell";
                DZDeailDownTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
                if (!cell) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DZDeailDownTableViewCell"  owner:self options:nil] lastObject];
                }
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                [cell loadData:subModel];
                return cell;
            }
                break;
            case  1:
            {
                static NSString *cellIdentifier=@"DZZheKouTableViewCell";
                DZZheKouTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
                if (!cell) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DZZheKouTableViewCell"  owner:self options:nil] lastObject];
                }
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                [cell loadZheKou:self.youhui YouHuiNeiRong:self.youhuineirong];
                //[cell loadData:self.zhekouModel];
                return cell;
            }
                break;
            default:
                return nil;
                break;
        }
        
    }else{
        if (indexPath.row==0) {
            static NSString *cellIdentifier=@"DZRoomDetailTableViewCell";
            DZRoomDetailTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!cell) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"DZRoomDetailTableViewCell"  owner:self options:nil] lastObject];
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell loadData:subModel];
            return cell;
            
        }else{
            static NSString *cellIdentifier=@"DZDeailDownTableViewCell";
            DZDeailDownTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!cell) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"DZDeailDownTableViewCell"  owner:self options:nil] lastObject];
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell loadData:subModel];
            return cell;
            
        }
 
    }
}

#pragma mark-UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isZhekou) {
        switch (indexPath.row) {
            case 0:
              return 385;
                break;
            case 2:
            {
                return initHeight;
            }
                break;
            case 1:
            {
              CGSize size=[Common calculateSize:self.youhuineirong maxWidth:267 fontSize:16];
                
                return size.height+90;
            }
                break;
                
                
            default:
                return 0;
                break;
        }
    }else{
        if (indexPath.row==0) {
            return 385;
        }else{

            return initHeight;
        }
 
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (UIView *)viewForLoadAnimationAtService:(RequestType)type{
    return self.view;
}
-(void)reloadTableViewHeight:(float)newHeight{
    initHeight=newHeight+10;
    [_listView beginUpdates];
    [_listView endUpdates];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
